package service

import (
	Mysql "gin/database"
	"gin/model"
	"gin/validate"
	"github.com/spf13/viper"
	"strings"
)

// ai媒体分析任务回调
func AiTaskCallBack(back validate.AITaskCallBack) (model.Media, error) {
	db := Mysql.DB
	media := model.Media{}
	result := db.Model(&model.Media{}).Where("task_uuid = ?", back.TaskUuid).Last(&media)
	if result.Error != nil {
		return media, result.Error
	}
	shareFoldName := viper.GetString("cdai.share_folder_name")

	result = db.Model(&model.Media{}).Where("id = ?", media.Id).Updates(model.Media{
		TaskResultFile: strings.Replace(back.ResultFile, shareFoldName, "static", 1),
	})
	if result.Error != nil {
		return media, result.Error
	}
	return media, nil
}
